package hashSet2;

import java.util.*;

public class HashSetDemo {
	public static void main(String[] args) {
		Set dog = new HashSet();
		Dog dog1 = new Dog("欧欧", "雪纳瑞");
		Dog dog2 = new Dog("菲菲", "拉布拉多");
		Dog dog3 = new Dog("敏敏", "泰迪");
		Dog dog4 = new Dog("旺财", "土狗");

		dog.add(dog1);
		dog.add(dog2);
		dog.add(dog3);
		dog.add(dog4);

		// 获得狗狗的总数
		System.out.println("共计有" + dog.size() + "条狗狗");
		System.out.println("分别是：");
		// 方法一：用增强型for逐条打印每条狗狗
		for (Object obj : dog) {
			Dog dogs = (Dog) obj;
			System.out.println(dogs.getName() + "\t" + dogs.getStrain());
		}

		System.out.println("*****************************");

		// 方法二：用iterator迭代器逐条打印每条狗狗
		Iterator iterator = dog.iterator();
		while (iterator.hasNext()) {
			Dog dogs = (Dog) iterator.next();
			System.out.println(dogs.getName() + "\t" + dogs.getStrain());
		}
	}
}
